
import websocket
import time
import threading

ws_server = 'ws://cn.loramanager.com:8765/uplink/'
appid = '027F000600010001'
ws_token = 'EmagaIOTBBl9B5JM4QAfFSBAZGJdPgEmFl7A354='
wsaddress = ws_server + appid + '/' + ws_token
SERVER_URL = wsaddress
def on_message(ws, message):
    print(message)


def on_error(ws, error):
    print(error)


def on_close(ws):
    print("### closed ###")


def on_open(ws):
    pass


if __name__ == "__main__":

    websocket.enableTrace(True)
    print(str(SERVER_URL))
    ws = websocket.WebSocketApp(SERVER_URL,
                                on_message=on_message,
                                on_error=on_error,
                                on_close=on_close)
    ws.on_open = on_open
    ws.run_forever()
'''
import asyncio
import websockets

async def client_get():
    ws_server = 'ws://cn.loramanager:8765/uplink/'
    appid = '027F000600010001'
    ws_token = 'EmagaIOTBBl9B5JM4QAfFSBAZGJdPgEmFl7A354='
    wsaddress = ws_server + appid +'/' + ws_token
    print(str(wsaddress))
    async with websockets.connect(wsaddress) as websocket:

        while True:
            rcv_message = await websocket.recv()
            print(rcv_message)



asyncio.get_event_loop().run_until_complete(client_get())
asyncio.get_event_loop().run_forever()
'''